import 'package:flutter/material.dart';
import 'package:wallpaper/components/my_tab_scroll_header.dart';
import 'package:wallpaper/pages/other/suyan/random_mage_list.dart';

class RandomImagePc extends StatefulWidget {
  const RandomImagePc({super.key});

  @override
  State<RandomImagePc> createState() => _RandomImageState();
}

class _RandomImageState extends State<RandomImagePc>
    with TickerProviderStateMixin {
  List childTypes = [];
  late TabController tabController;
  int activeIndex = 0;
  PageController pageController = PageController(initialPage: 0);
  // 1：美女，2：动漫，3：风景，4：游戏，5：明星，6：机械，7：动物，8：文字，9：城市，10：视觉，11：物语，：12：情感，13：设计，14：男人
  List types = [
    [1, '美女'],
    [2, '动漫'],
    [3, '风景'],
    [4, '游戏'],
    [5, '明星'],
    [6, '机械'],
    [7, '动物'],
    [8, '文字'],
    [9, '城市'],
    [10, '视觉'],
    [11, '物语'],
    [12, '情感'],
    [13, '设计'],
    [14, '男人'],
  ];
  List<String> subList = [];

  @override
  void initState() {
    super.initState();
    subList = types.map((e) => e[1].toString()).toList();
    tabController = TabController(length: subList.length, vsync: this);
    tabController.addListener(() {
      setState(() {
        activeIndex = tabController.index;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context).colorScheme;
    return Scaffold(
      appBar: AppBar(
          toolbarHeight: 40,
          backgroundColor: theme.primaryContainer,
          surfaceTintColor: theme.primaryContainer,
          elevation: 0,
          title: MyTabScrollHeader(
              tabController: tabController,
              tabs: subList,
              onTap: (index) {
                pageController.jumpToPage(index);
              })),
      body: Column(
        children: [
          Expanded(
              child: PageView(
            controller: pageController,
            children: [
              for (var i = 0; i < subList.length; i++)
                RandomMageList(
                  format: types[i][0],
                  screen: 1,
                ),
            ],
            onPageChanged: (index) {
              setState(() {
                activeIndex = index;
              });
              tabController.animateTo(index);
            },
          ))
        ],
      ),
    );
  }
}
